package com.fishery.processing.util;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fishery.processing.entity.Job;
import com.fishery.processing.entity.MaterialInventory;

/**
 * @author run
 * @since 2021/3/13 10:10
 */
public class WrapperUtil {

    public static UpdateWrapper<MaterialInventory> buildMaterialWrapper(Job job,boolean isAdd){
        return buildMaterialWrapper(job.getMaterialId(), isAdd ? job.getMaterialWeight() : -job.getMaterialWeight());
    }

    public static UpdateWrapper<MaterialInventory> buildMaterialWrapper(MaterialInventory material){
        return buildMaterialWrapper(material.getMaterialId(), material.getMaterialWeight());
    }

    public static UpdateWrapper<MaterialInventory> buildMaterialWrapper(String materialId, Double weight){
        UpdateWrapper<MaterialInventory> wrapper = new UpdateWrapper<>();
        return wrapper.eq("material_id", materialId)
                .ge("material_weight", weight)
                .setSql("material_weight = material_weight + " + weight);
    }
}
